//
//  SimpleHeaderView.m
//  ForestPack
//
//  Created by jimmy on 2018/7/11.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SimpleHeaderView.h"
#import "FPCustomButton.h"
#import "Masonry.h"

@interface SimpleHeaderView()

//@property (nonatomic,strong)  UILabel  * titleLabel;
@property (nonatomic,strong)  UIButton  * moreBtn;

@end

@implementation SimpleHeaderView

+(SimpleHeaderView *)headerViewWithTitle:(NSString *)title withHeight:(CGFloat)height
{
    SimpleHeaderView *headerView = [[SimpleHeaderView alloc] init];
    
    UIImageView * leftImageV = [[UIImageView alloc] init];
    leftImageV.image = [UIImage imageNamed:@"红色矩形"];
    leftImageV.contentMode = UIViewContentModeScaleToFill;
    [headerView addSubview:leftImageV];
    [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView);
        make.top.equalTo(@((height - 23)/2));
        make.width.equalTo(@(3));
        make.height.equalTo(@23);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [titleLabel setText: title];
    titleLabel.numberOfLines = 0;
    titleLabel.textColor = FONTCOLOR_BLACK;
    titleLabel.font = Kfont(18);
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView.mas_left).offset(13);
        make.top.equalTo(@((height - 23)/2));
        make.width.equalTo(@(SCREEN_WIDTH - 60));
        make.height.equalTo(@23);
    }];
    
    
    
    UILabel *lineLabel = [[UILabel alloc] init];
    lineLabel.backgroundColor = RGB_COLOR(220,220,220);
    [headerView addSubview:lineLabel];
    [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView.mas_left);
        make.top.equalTo(headerView.mas_bottom);
        make.right.equalTo(headerView.mas_right);
        make.height.equalTo(@1);
    }];
    
    return headerView;
    
}

@end


@interface SimpleHeaderWithBtn()


@end

@implementation SimpleHeaderWithBtn

-(void)moreClicked
{
    if (_moreClick) {
        _moreClick();
    }
}

+(SimpleHeaderWithBtn *)headerViewWithTitle:(NSString *)title withHeight:(CGFloat)height
{
    SimpleHeaderWithBtn *headerView = [[SimpleHeaderWithBtn alloc] init];
    headerView.backgroundColor = [UIColor whiteColor];
    UIImageView * leftImageV = [[UIImageView alloc] init];
    leftImageV.image = [UIImage imageNamed:@"红色矩形"];
    leftImageV.contentMode = UIViewContentModeScaleToFill;
    [headerView addSubview:leftImageV];
    [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView);
        make.top.equalTo(@((height - 23)/2));
        make.width.equalTo(@(3));
        make.height.equalTo(@23);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [titleLabel setText: title];
    titleLabel.numberOfLines = 0;
    titleLabel.textColor = FONTCOLOR_BLACK;
    titleLabel.font = Kfont(18);
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView.mas_left).offset(13);
        make.top.equalTo(@((height - 23)/2));
        make.width.equalTo(@(SCREEN_WIDTH - 80));
        make.height.equalTo(@23);
    }];
    
    FPLeftRightButton * rightBtn = [FPLeftRightButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setImage:[UIImage imageNamed:@"更多灰色"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"更多" forState:UIControlStateNormal];
    [rightBtn setTitleColor:RGB_COLOR(153,153,153) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [rightBtn addTarget:headerView action:@selector(moreClicked) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(headerView.mas_right).offset(-16);
        make.centerY.equalTo(headerView.mas_centerY);
        make.height.equalTo(@(30));
        make.width.equalTo(@(50));
    }];
    
    return headerView;
}


@end

